//
//  NewSellerOrderListViewController.m
//  智积分
//
//  Created by apple on 2018/5/15.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "NewSellerOrderListViewController.h"
#import "DetailOrderInfoViewController.h"
#import "NewSellerAllRecordViewController.h"
#import "NewSellerOrderScrollTableViewCell.h"
#import "NewSellerPersonlistTableViewCell.h"
#import "NewSellerShortOrdersTableViewCell.h"
#import "DetailCodeStoreOrderViewController.h"
#import "DealInfoViewController.h"
static NSString *firstnewsellerorderscrollcellIndentifier = @"firstnewsellerorderscrollcellIndentifier";
static NSString *firstnewsellerorderPersonlistcellindentifier = @"firstnewsellerorderPersonlistcellindentifier";
static NSString *secondnewsellerorderscrollcellIndentifier = @"secondnewsellerorderscrollcellIndentifier";
static NSString *NewSellerShortOrdersTableViewCellindentifier = @"NewSellerShortOrdersTableViewCellindentifier";
static NSString *thirdnewsellerorderscrollcellIndentifier = @"thirdnewsellerorderscrollcellIndentifier";
static NSString *NewSellerLongOrdersTableViewCellindentifier = @"NewSellerLongOrdersTableViewCellindentifier";
@interface NewSellerOrderListViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
@property (nonatomic ,retain)UIScrollView *BGScroll;
@property (nonatomic ,retain)NSMutableArray *MainViews;
@property (nonatomic ,assign)NSInteger currentSegNum;
@property (nonatomic ,retain)UIButton *currentSeg;
//@property (nonatomic ,retain)UIView *headerPersonlistview;
@property (nonatomic ,retain)UIView *noticeView;
@property (nonatomic ,retain)NSMutableArray *segs;
@property (nonatomic ,retain)NSMutableDictionary *moneyData;//门店营业额数据
@property (nonatomic ,retain)NSMutableDictionary *SecMoneyData;//商城营业额数据
@property (nonatomic ,retain)NSMutableArray *buylist;//首页数据列表
@property (nonatomic ,retain)NSMutableArray *shoporders;//商城数据列表
@property (nonatomic ,retain)NSMutableArray *integralLsit;//分销商城数据列表
@property (nonatomic ,retain)NSMutableDictionary *CodeStoreMoneyData;//分销商城营业额数据
@property (nonatomic ,assign)NSInteger currentFirstPgae;
@property (nonatomic ,assign)NSInteger currentSecondPage;
@property (nonatomic ,assign)NSInteger currentThirdPage;
@property (nonatomic ,assign)NSInteger currentFourthPage;
@property (nonatomic ,retain)UIButton *ringbtn;
@property (nonatomic ,assign)BOOL FirstLoaded;
@property (nonatomic ,assign)BOOL SecondLoaded;
@property (nonatomic ,assign)BOOL ThirdLoaded;


@end

@implementation NewSellerOrderListViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
     [self selfSellterInfoLoad];
    [self moneyDataLoad];
    [self storeMoneyLoad];
    if (cx_hit == 812) {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    }
    else{
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    };
}


/**
 判断有无tableview无 则加载
 */
-(void)newRefresh{
    dispatch_async(dispatch_get_main_queue(), ^{
        if([[_MainViews objectAtIndex:0] isKindOfClass:[UITableView class]]){
    [[(UITableView *)[_MainViews objectAtIndex:0] mj_header] beginRefreshing];
        }
        if([[_MainViews objectAtIndex:1] isKindOfClass:[UITableView class]]){
            [[(UITableView *)[_MainViews objectAtIndex:1] mj_header] beginRefreshing];
        }
        if(cxsingler.sellersegnum > 2){
        if([[_MainViews objectAtIndex:2] isKindOfClass:[UITableView class]]){
            [[(UITableView *)[_MainViews objectAtIndex:2] mj_header] beginRefreshing];
        }
        }
     });
}



/**
 获取商户个人信息
 */
-(void)selfSellterInfoLoad{
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel getSllerInfo];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        if ([result isEqual:@"success"]) {
            NSDictionary *partdic = cxsingler.DicData;
            NSArray *list = [partdic allKeys];
            for (NSString *key in list) {
                NSLog(@"%@ ----- %@",[partdic[key]  class],key);
                [cxsingler.loginrequest setObject:[self Nnll:partdic[key] withPlace:@""] forKey:key];
            }
            weakSelf.centerTitle.text = cxsingler.loginrequest[@"name"];
        }
        else{
            [SVProgressHUD showErrorWithStatus:result];
        }
    };
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _FirstLoaded = _SecondLoaded = _ThirdLoaded = NO;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newRefresh) name:@"numberrefresh" object:nil];
    _moneyData = [@{
                    @"balanceArrived":@" 0",
                    @"bankArrived" : @"0",
                    @"orderCount" : @"0",
                    @"totalAmount" : @"0",
                    @"userCount" : @"0"} mutableCopy];
    _CodeStoreMoneyData = [@{
                             @"totalPayAmount" : @"0",
                             @"totalPayIntegral" : @"0",
                             @"totalPayItemNum" : @"0",
                             @"totalStat" : @"0",
                             @"tradeCount" : @"0"
                             } mutableCopy];
    _currentSecondPage = _currentFirstPgae = _currentThirdPage = _currentFourthPage = 1;
    _SecMoneyData = [@{
                       @"total_cash" : @"0",
                       @"total_goods" : @"0",
                       @"total_integral" : @"0",
                       @"trade_cnt" : @"0"}  mutableCopy];
    _integralLsit = [NSMutableArray array];
    [self viewLoad];
    [self dataLoad];
}



#pragma mark--数据请求
-(void)dataLoad{
    
    //门店部分
    [self moneyDataLoad];
    [self buylistLoadWithmore:NO];
    //商城部分
    [self storeMoneyLoad];
    [self StoreOrderListLoadWithmore:NO];
    if(cxsingler.sellersegnum > 2){
    //积分商城部分
    [self CodeMoneyLoad];
    [self CodeOrderListLoadWithMore:NO];
    }
}

#pragma mark--资金数据获取
-(void)moneyDataLoad{
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel getStoreDetailMoney];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        if ([result isEqual:@"success"]) {
            weakSelf.moneyData = [cxsingler.DicData mutableCopy];
            dispatch_async(dispatch_get_main_queue(), ^{
                                if ([weakSelf.MainViews[0] isKindOfClass:[UITableView class]]) {
                                    [weakSelf.MainViews[0] reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
                                }
                                if ([weakSelf.MainViews[1] isKindOfClass:[UITableView class]]) {
                                    [weakSelf.MainViews[1] reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
                                }
                if ([weakSelf.MainViews[2] isKindOfClass:[UITableView class]]) {
                    [weakSelf.MainViews[2] reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
                }
                if ([weakSelf.MainViews[3] isKindOfClass:[UITableView class]]) {
                    [weakSelf.MainViews[3] reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
                }
            });
        }
        else{
            [SVProgressHUD showErrorWithStatus:result];
        }
    };
}

#pragma mark--消费列表获取//门店
-(void)buylistLoadWithmore:(BOOL)more{
    NSInteger currentpage = 0;
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    if (!more) {
        currentpage = _currentFirstPgae = 1;
    }
    else{
        currentpage = _currentFirstPgae + 1;
    }
    ;
    [netmodel getStoreDetailBuessesswithpage:currentpage withOnlyToday:YES];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        weakSelf.FirstLoaded = YES;
        if (more) {
            [[(UITableView *)[weakSelf.MainViews objectAtIndex:0] mj_footer] endRefreshing];
        }
        else{
            [[(UITableView *)[weakSelf.MainViews objectAtIndex:0] mj_header] endRefreshing];
        }
        if ([result isEqual:@"success"]) {
            NSArray *list = cxsingler.ArraryData;
            if (cxsingler.ArraryData.count > 0) {
                weakSelf.currentFirstPgae = currentpage;
                if (!more) {
                    weakSelf.buylist = [NSMutableArray array];
                }
                for (NSDictionary *dic in list) {
                    [weakSelf.buylist addObject:dic];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    [(UITableView *)[weakSelf.MainViews objectAtIndex:0] reloadData];
                });
            }
            else if (!more){
                weakSelf.currentFirstPgae = currentpage;
                weakSelf.buylist = [NSMutableArray array];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [(UITableView *)[weakSelf.MainViews objectAtIndex:0] reloadData];
                });
            }
        }
        else{
            [SVProgressHUD showErrorWithStatus:result];
        }
    };
}

#pragma mark--商店资金part
-(void)storeMoneyLoad{
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel NewSellerStoreMoneyinfowithShopID:cxsingler.loginrequest[@"admin"][@"shop_id"]];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        if ([result isEqual:@"success"]) {
            weakSelf.SecMoneyData = [cxsingler.DicData mutableCopy];
            [weakSelf reloadMoneyWithSeg:1];
        }
        
    };
}

/**
 更新某部分segment money 部分

 @param segnum 第几个segment
 */
-(void)reloadMoneyWithSeg:(NSInteger)segnum{
    [(UITableView *)[_MainViews objectAtIndex:segnum] reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma mark--商店订单列表
-(void)StoreOrderListLoadWithmore:(BOOL)more{
    NSInteger newpage = 0;
    if (!more) {
        newpage = _currentSecondPage = 1;
    }
    else{
        newpage = _currentSecondPage + 1;
    }
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel NewSellerStoreGetOrderlistByshopID:cxsingler.loginrequest[@"admin"][@"shop_id"] WithPage:newpage withOnlyToday:YES];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        weakSelf.SecondLoaded = YES;
        UITableView *tableview = weakSelf.MainViews[1];
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([tableview.mj_header isRefreshing]) {
                [tableview.mj_header endRefreshing];
            }
            else if([tableview.mj_footer isRefreshing]){
                [tableview.mj_footer endRefreshingWithCompletionBlock:^{
                    
                }];
            }
        });
        if ([result isEqual:@"success"]) {
            NSArray *resultList = cxsingler.ArraryData;
            if(resultList.count > 0){
                weakSelf.currentSecondPage = newpage;
            }
            if (more) {
                if (resultList.count > 0) {
                    for (NSInteger index = 0; index < resultList.count; index ++) {
                        [weakSelf.shoporders addObject:resultList[index]];
                    }
                }
            }
            else{
                if (resultList.count > 0) {
                    weakSelf.shoporders = [NSMutableArray array];
                    weakSelf.shoporders = [resultList mutableCopy];
                }
                else {
                    weakSelf.currentSecondPage = newpage;
                    weakSelf.shoporders = [NSMutableArray array];
                }
            }
            [(UITableView *)[weakSelf.MainViews objectAtIndex:1] reloadData];
        }
        else{
            [SVProgressHUD showErrorWithStatus:result];
        }
    };
}



#pragma mark--分销商城订单列表
-(void)CodeMoneyLoad{
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel GetCodeStoreMoneyInfoByShopID:cxsingler.loginrequest[@"admin"][@"shop_id"]];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        if ([result isEqual:@"success"]) {
            weakSelf.CodeStoreMoneyData = [cxsingler.DicData mutableCopy];
            [(UITableView *)weakSelf.MainViews[2] reloadData];
        }
        else{
            
        }
    };
}

-(void)CodeOrderListLoadWithMore:(BOOL)More{
    NSInteger page = _currentThirdPage + 1;
    if (!More) {
        page = 1;
    }
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel GetCodeStoreListWithCurrentPage:page withShopID:cxsingler.loginrequest[@"admin"][@"shop_id"]];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        weakSelf.ThirdLoaded = YES;
        if ([[(UITableView *)weakSelf.MainViews[2] mj_header] isRefreshing]) {
            [[(UITableView *)weakSelf.MainViews[2] mj_header] endRefreshing];
        }
        else if ([[(UITableView *)weakSelf.MainViews[2] mj_footer] isRefreshing]){
            [[(UITableView *)weakSelf.MainViews[2] mj_footer] endRefreshing];
        }
        if ([result isEqual:@"success"]) {
            NSArray *partList = [cxsingler.ArraryData copy];
            if ([partList count] > 0) {
                weakSelf.currentThirdPage = page;
                if (!More) {
                    weakSelf.integralLsit = [NSMutableArray array];
                }
                for (NSDictionary *partDic in partList) {
                    [weakSelf.integralLsit addObject:partDic];
                }
                [(UITableView *)weakSelf.MainViews[2] reloadData];
            }
            else if (!More){
                weakSelf.currentThirdPage = page;
                weakSelf.integralLsit = [NSMutableArray array];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [(UITableView *)[weakSelf.MainViews objectAtIndex:2] reloadData];
                });
            }
        }
        else{
            
        }
    };
}



-(void)codestore{
    UITableView *tableview = _MainViews[2];
    if ([tableview.mj_header isRefreshing]) {
        [tableview.mj_header endRefreshing];
    }
    else if ([tableview.mj_footer isRefreshing]){
        [tableview.mj_footer endRefreshing];
    }
    [tableview reloadData];
}



-(instancetype)initInChildWithFrame:(CGRect)frame{
    self = [super init];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.frame = frame;
    return self;
}

-(void)viewLoad{
    _MainViews = [NSMutableArray arrayWithObjects:@"",@"",@"",@"", nil];
    _segs = [NSMutableArray array];
    self.view.backgroundColor = [CXSinglerModel colorWithHex:@"f3f4f6" alpha:1];
    _currentSegNum = 0;
    [self setNavigationViewWithTitle:cxsingler.loginrequest[@"admin"][@"name"] WithCanPop:NO WithPopData:@"" WithPopisString:YES WithHasRightOperation:YES WithrightOperationData:@"" WithRightisString:NO WithNavigationColor:[UIColor whiteColor] withBgView:self.view];
    
    _ringbtn = [[UIButton alloc] initWithFrame:CGRectMake(cx_wid - 44, cxsingler.topdis, 44, 44)];
    [self.view addSubview:_ringbtn];
    WEAKSELF;
    [_ringbtn cx_eventsBlockHandler:^{
        NetWorkModel *netmodel = [[NetWorkModel alloc] init];
        [netmodel changeringstatus:!weakSelf.ringbtn.selected];
        WEAKSELF;
        netmodel.sendMessage = ^(NSString *result) {
            if ([result isEqual:@"success"]) {
                weakSelf.ringbtn.selected = !weakSelf.ringbtn.selected;
                cxsingler.shouldRing = weakSelf.ringbtn.selected;
                [SVProgressHUD showSuccessWithStatus:@"闹铃状态修改成功"];
            }
            else{
                [SVProgressHUD showErrorWithStatus:result];
            }
        };
        [self.view endEditing:YES];
    } forControlEvents:UIControlEventTouchUpInside];
    [_ringbtn setImage:[UIImage imageNamed:@"header_notice"] forState:UIControlStateSelected];
    [_ringbtn setImage:[UIImage imageNamed:@"header_silence"] forState:UIControlStateNormal];
    if ([cxsingler.loginrequest[@"voiceState"] boolValue] == 1) {
        _ringbtn.selected = YES;
        cxsingler.shouldRing = YES;
    }
    else{
        _ringbtn.selected = NO;
        cxsingler.shouldRing = NO;
    }
    
    self.centerTitle.textColor = [CXSinglerModel colorWithHex:@"000000" alpha:1];
    [self segmentLoad];
    [self mainViewLoad];
}

-(void)mainViewLoad{
    if (!_BGScroll) {
        _BGScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, cxsingler.topdis + 44 + 34, cx_wid, cx_hit - cxsingler.topdis - 44 - 34 - 50)];
        _BGScroll.delegate = self;
        _BGScroll.contentSize = CGSizeMake(cx_wid * cxsingler.sellersegnum, cx_hit - cxsingler.topdis - 44 - 34 - 50);
        _BGScroll.showsVerticalScrollIndicator = NO;
        _BGScroll.showsHorizontalScrollIndicator = NO;
        _BGScroll.pagingEnabled = YES;
        [self.view addSubview:_BGScroll];
        [self loadsegbyNum:0];
        [self loadsegbyNum:1];
        if(cxsingler.sellersegnum > 2){
        [self loadsegbyNum:2];
        }
        //        [self loadsegbyNum:3];
    }
    
}

-(void)loadsegbyNum:(NSInteger)segnum{
    //    switch (segnum) {
    //        case 0:
    //            {
    if ([[_MainViews objectAtIndex:segnum] isEqual:@""]) {
        UITableView *MainView = [[UITableView alloc] initWithFrame:CGRectMake(cx_wid * segnum, 0, cx_wid, cx_hit - cxsingler.topdis - 44 - 34 - 50 -cxsingler.bottomdis)];
        [MainView placeImageWithData:@"404" withOffset:100];
        MainView.placeImageView.hidden = YES;

        
        MainView.estimatedRowHeight = 0;
        if (@available(iOS 11.0, *)) {
            MainView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        MainView.separatorStyle = UITableViewCellSeparatorStyleNone;
        MainView.backgroundColor = [CXSinglerModel colorWithHex:@"f3f4f6" alpha:1];
        MainView.delegate = self;
        MainView.dataSource = self;
        if (segnum == 0) {
            [MainView registerClass:[NewSellerOrderScrollTableViewCell class] forCellReuseIdentifier:firstnewsellerorderscrollcellIndentifier];
            [MainView registerClass:[NewSellerPersonlistTableViewCell class] forCellReuseIdentifier:firstnewsellerorderPersonlistcellindentifier];
        }
        else if (segnum == 1){
            [MainView registerClass:[NewSellerOrderScrollTableViewCell class] forCellReuseIdentifier:secondnewsellerorderscrollcellIndentifier];
            [MainView registerClass:[NewSellerShortOrdersTableViewCell class] forCellReuseIdentifier:NewSellerShortOrdersTableViewCellindentifier];
        }
        else if (segnum == 2){
             if(cxsingler.sellersegnum > 2){
            [MainView registerClass:[NewSellerOrderScrollTableViewCell class] forCellReuseIdentifier:thirdnewsellerorderscrollcellIndentifier];
            [MainView registerClass:[NewSellerShortOrdersTableViewCell class] forCellReuseIdentifier:NewSellerLongOrdersTableViewCellindentifier];
             }
        }
        else if (segnum == 3){
            
        }
        WEAKSELF;
        MJRefreshGifHeader *Gifheader = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            if (segnum == 0) {
                [weakSelf moneyDataLoad];
                [weakSelf buylistLoadWithmore:NO];
            }
            else if (segnum == 1){
                [weakSelf storeMoneyLoad];
                [weakSelf StoreOrderListLoadWithmore:NO];
            }
            else if (segnum == 2){
                if(cxsingler.sellersegnum > 2){
                [weakSelf CodeMoneyLoad];
                [weakSelf CodeOrderListLoadWithMore:NO];
                }
            }
        }];
        MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
            if (segnum == 0){
                [weakSelf buylistLoadWithmore:YES];
            }
            else if (segnum == 1){
                [weakSelf StoreOrderListLoadWithmore:YES];
            }
            else if (segnum == 2){
                 if(cxsingler.sellersegnum > 2){
                [weakSelf CodeOrderListLoadWithMore:YES];
                 }
            }
        }];
        [Gifheader setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
        [Gifheader setTitle:@"松开刷新" forState:MJRefreshStatePulling];
        [Gifheader setTitle:@"刷新中……" forState:MJRefreshStateRefreshing];
        [footer setTitle:@"上拉加载更多" forState:MJRefreshStateIdle];
        [footer setTitle:@"松开加载更多" forState:MJRefreshStatePulling];
        [footer setTitle:@"加载更多中……" forState:MJRefreshStateRefreshing];
        MainView.mj_header = Gifheader;
        MainView.mj_footer = footer;
        [_BGScroll addSubview:MainView];
        if (@available(iOS 11.0, *)) {
            _BGScroll.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        [_MainViews replaceObjectAtIndex:segnum withObject:MainView];
    }
    else{
        [(UITableView *)[_MainViews objectAtIndex:segnum] reloadData];
    }
    
}

#pragma mark--tableview代理开始
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger vcnum = [_MainViews indexOfObject:tableView];
    if (vcnum == 0) {
        if (section == 0) {
            return 1;
        }
        else{
            if (_buylist.count == 0 && _FirstLoaded) {
                tableView.placeImageView.hidden = NO;
            }
            else{
                tableView.placeImageView.hidden = YES;
            }
            return _buylist.count;
        }
    }
    else if(vcnum == 1){
        if (section == 0) {
            return 1;
        }
        else{
            if (_shoporders.count == 0 && _SecondLoaded) {
                tableView.placeImageView.hidden = NO;
            }
            else{
                tableView.placeImageView.hidden = YES;
            }
            return _shoporders.count;
        }
    }
    else if(vcnum == 2){
        if (section == 0) {
            return 1;
        }
        else{
            if (_integralLsit.count == 0 && _ThirdLoaded) {
                tableView.placeImageView.hidden = NO;
            }
            else{
                tableView.placeImageView.hidden = YES;
            }
            return _integralLsit.count;
        }
    }
    else if(vcnum == 3){
        if (section == 0) {
            return 1;
        }
        else{
            return 3;
        }
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger vcnum = [_MainViews indexOfObject:tableView];
    NSInteger sec = indexPath.section;
    NSInteger row = indexPath.row;
    if (sec == 0) {
        return cx_wid / 378 * 185 + 10;
    }
    else{
        if (vcnum == 0) {
            return 54;
        }
        else if (vcnum == 1){
            NSInteger num = [_shoporders[row][@"order_lst"] count];
            return 150 + num * 84;
        }
        else{
            return 150 +  84;
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    NSInteger vcnum = [_MainViews indexOfObject:tableView];
    if (vcnum == 0 || vcnum == 1) {
        if (section == 1) {
            return 44;
        }
    }
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSInteger segnum = [_MainViews indexOfObject:tableView];
    if (segnum == 0 || segnum == 1) {
        if (section == 1) {
//            if (!_headerPersonlistview) {
                UIView *headerPersonlistview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, 44)];
                headerPersonlistview.backgroundColor = [UIColor whiteColor];
                UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 14, 60, 16)];
                UIButton *deslabel = [[UIButton alloc] initWithFrame:CGRectMake(cx_wid - 12 - 60, 14,60, 16)];
                WEAKSELF;
                [deslabel cx_eventsBlockHandler:^{
                    NewSellerAllRecordViewController *nextVC = [[NewSellerAllRecordViewController alloc] initWithtype:segnum];
                        [weakSelf.navigationController pushViewController:nextVC animated:YES];
                } forControlEvents:UIControlEventTouchUpInside];
                timelabel.text = @"今日";
                //                deslabel.text = @"对账";
                [deslabel setTitle:@"对账" forState:UIControlStateNormal];
                deslabel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
                timelabel.font = [UIFont systemFontOfSize:15];
                deslabel.titleLabel.font = [UIFont systemFontOfSize:15];
                //                deslabel.textColor = [CXSinglerModel colorWithHex:@"999999" alpha:1];
                [deslabel setTitleColor:[CXSinglerModel colorWithHex:@"999999" alpha:1] forState:UIControlStateNormal];
                timelabel.textColor = [UIColor blackColor];
                UIView *layerview = [[UIView alloc] initWithFrame:CGRectMake(0, 43, cx_wid, 1)];
                layerview.backgroundColor = [CXSinglerModel colorWithHex:@"f3f4f6" alpha:1];
                [headerPersonlistview addSubview:layerview];
                [headerPersonlistview addSubview:timelabel];
                [headerPersonlistview addSubview:deslabel];
//            }
            return headerPersonlistview;
        }
    }
    UIView *nilview = [[UIView alloc] initWithFrame:CGRectZero];
    return nilview;
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    NSInteger sec = indexPath.section;
    NSInteger vcnum = [_MainViews indexOfObject:tableView];
    if (vcnum == 0) {
        if (sec == 0) {
            NewSellerOrderScrollTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:firstnewsellerorderscrollcellIndentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.money.text = [NSString stringWithFormat:@"%.2lf",[_moneyData[@"totalAmount"] floatValue] / 100];
            cell.ordersNum.text = [NSString stringWithFormat:@"%ld",[_moneyData[@"orderCount"] integerValue]];
            cell.dealsNum.text = [NSString stringWithFormat:@"%ld",[_moneyData[@"userCount"] integerValue]];
            cell.TodayRiseCode.text = [NSString stringWithFormat:@"%ld",[[self Nnll:_moneyData[@"balanceArrived"] withPlace:@"0"] integerValue]];
            cell.TodayRiseMoney.text = [NSString stringWithFormat:@"%.2lf",([[self Nnll:_moneyData[@"bankArrived"] withPlace:@"0"] floatValue]) / 100];
            return cell;
        }
        else {
            NSMutableDictionary *part = _buylist[row];
            NewSellerPersonlistTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:firstnewsellerorderPersonlistcellindentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.name.text =  part[@"userName"];;
            cell.time.text = [self gettimeByInter:[[[NSString stringWithFormat:@"%@",part[@"createTime"]] substringWithRange:NSMakeRange(0, 10)] integerValue]];
            cell.money.text = [NSString stringWithFormat:@"+%.2lf",[part[@"price"] floatValue] / 100];
            [cell.header sd_setBackgroundImageWithURL:[NSURL URLWithString:part[@"avatar"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"logo1"]];
            return cell;
        }
        
    }
    else if (vcnum == 1){
        if (sec == 0) {
            NewSellerOrderScrollTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:secondnewsellerorderscrollcellIndentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.money.text = [NSString stringWithFormat:@"%.2lf",([[self Nnll:_SecMoneyData[@"total_integral"] withPlace:@"0"] floatValue] + [[self Nnll:_SecMoneyData[@"total_cash"] withPlace:@"0"] floatValue]) / 100];
            cell.ordersNum.text = [NSString stringWithFormat:@"%@",[self Nnll:_SecMoneyData[@"trade_cnt"] withPlace:@"0"]];
            cell.dealsNum.text = [NSString stringWithFormat:@"%@",[self Nnll:_SecMoneyData[@"total_goods"] withPlace:@"0"]];
            cell.TodayRiseCode.text = [NSString stringWithFormat:@"%ld",[[self Nnll:_SecMoneyData[@"total_integral"] withPlace:@"0"] integerValue]];
            cell.TodayRiseMoney.text = [NSString stringWithFormat:@"%.2lf",([[self Nnll:_SecMoneyData[@"total_cash"] withPlace:@"0"] floatValue]) / 100];
            return cell;
        }
        else {
            NSDictionary *part = _shoporders[row];
            NewSellerShortOrdersTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NewSellerShortOrdersTableViewCellindentifier];
            cell.clipsToBounds = YES;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if ([part[@"parent_order_id"] isEqual:@"EA8352087"]) {
                
            }
            cell.time.text = part[@"create_time"];
            cell.ordernum.text = part[@"parent_order_id"];
            cell.buyyer.text = [NSString stringWithFormat:@"买家:%@",part[@"nickname"]];
            cell.status.text = part[@"order_lst"][0][@"delive_goods_status_str"];
            [cell loadProductions:part[@"order_lst"]];
            //            cell.productionname.text = part[@"order_lst"][0][@"goods_name"];
            //            cell.productioninfo.text = part[@"order_lst"][0][@"goods_attr"];
            //            cell.num.text = part[@"goods_num"];
            //            [cell.productionimg sd_setImageWithURL:[NSURL URLWithString:part[@"order_lst"][0][@"goods_sm_img"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"logo2"]];
            NSString *transmoney = @"免费";
            if ([part[@"mix_all_freight_price"] floatValue] > 0) {
                transmoney = [NSString stringWithFormat:@"%.2lf",[part[@"mix_all_freight_price"] floatValue] / 100];
            }
            cell.transMoney.text = [NSString stringWithFormat:@"%@",transmoney];
            
            NSString *price = [NSString stringWithFormat:@"%.2lf",([part[@"payment_details"][@"pay_amount"] floatValue] + [part[@"payment_details"][@"pay_integral"] floatValue]) / 100];
            NSInteger count = 0;
            for (NSDictionary *dic in part[@"order_lst"]) {
                count = count + [dic[@"goods_num"] integerValue];
            }
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"共%ld件,合计:￥%@",count,price]];
            [str addAttribute:NSForegroundColorAttributeName value:[CXSinglerModel colorWithHex:@"666666" alpha:1] range:NSMakeRange(0,str.length)];
            [str addAttribute:NSForegroundColorAttributeName value:[CXSinglerModel colorWithHex:@"#FE4438" alpha:1] range:NSMakeRange(str.length - price.length - 1,price.length + 1)];
            cell.costmoney.attributedText = str;
            
            return cell;
        }
        
    }
    else if (vcnum == 2){
        if (sec == 0) {
            NewSellerOrderScrollTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:thirdnewsellerorderscrollcellIndentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.money.text = [NSString stringWithFormat:@"%.2lf",[_CodeStoreMoneyData[@"totalStat"] floatValue]/ 100];
            cell.ordersNum.text = [NSString stringWithFormat:@"%@",_CodeStoreMoneyData[@"tradeCount"]];
            cell.dealsNum.text = [NSString stringWithFormat:@"%@",_CodeStoreMoneyData[@"totalPayItemNum"]];
            cell.TodayRiseCode.text = [NSString stringWithFormat:@"%ld",[[self Nnll:_CodeStoreMoneyData[@"totalPayIntegral"] withPlace:@"0"] integerValue]];
            cell.TodayRiseMoney.text = [NSString stringWithFormat:@"%.2lf",([[self Nnll:_CodeStoreMoneyData[@"totalPayAmount"] withPlace:@"0"] floatValue]) / 100];
            return cell;
        }
        else{
            NSDictionary *part = _integralLsit[row];
            NewSellerShortOrdersTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NewSellerLongOrdersTableViewCellindentifier];
            cell.clipsToBounds = YES;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.time.text = [self gettimeByInter:[part[@"createDate"] integerValue]];
            cell.ordernum.text = part[@"tradeNo"];
            cell.buyyer.text = [NSString stringWithFormat:@"买家:%@",part[@"userName"]];
            NSString *status = [self statusByWord:part[@"tradeStatus"]];
            cell.status.text = status;//
            NSDictionary *partData = [NSDictionary dictionaryWithObjectsAndKeys:part[@"itemTitle"],@"goods_name",@"",@"goods_attr",[NSString stringWithFormat:@"%@",part[@"num"]],@"goods_num",[NSString stringWithFormat:@"http:%@",part[@"url"]],@"goods_sm_img", nil];
            [cell loadProductions:@[partData]];
            NSString *transmoney = @"包邮";
            cell.transMoney.text = transmoney;
            //            if ([part[@"mix_all_freight_price"] floatValue] > 0) {
            //                transmoney = part[@"mix_all_freight_price"];
            //            }
            //            cell.transMoney.text = [NSString stringWithFormat:@"%@",transmoney];
            
            //            NSString *price = [NSString stringWithFormat:@"%.2lf",([part[@"payment_details"][@"pay_amount"] floatValue] + [part[@"payment_details"][@"pay_integral"] floatValue]) / 100];
            //            NSInteger count = 0;
            //            for (NSDictionary *dic in part[@"order_lst"]) {
            //                count = count + [dic[@"goods_num"] integerValue];
            //            }
            NSString *price = [NSString stringWithFormat:@"%.2lf",[part[@"price"] floatValue] / 100 * [part[@"num"]  integerValue]];
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"共%@件,合计:￥%@",part[@"num"],price]];
            [str addAttribute:NSForegroundColorAttributeName value:[CXSinglerModel colorWithHex:@"666666" alpha:1] range:NSMakeRange(0,str.length)];
            [str addAttribute:NSForegroundColorAttributeName value:[CXSinglerModel colorWithHex:@"#FE4438" alpha:1] range:NSMakeRange(str.length - price.length - 1,price.length + 1)];
            cell.costmoney.attributedText = str;
            
            return cell;
        }
        
    }
    //    else if (vcnum == 3){
    //        if (sec == 0) {
    //            NewSellerOrderScrollTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:firstnewsellerorderscrollcellIndentifier];
    //            cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //            return cell;
    //        }
    //        else if(_currentSegNum == 0){
    //            NewSellerPersonlistTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:firstnewsellerorderPersonlistcellindentifier];
    //            cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //            cell.name.text = @"我的天空";
    //            cell.time.text = @"2016-11-15 12:38";
    //            cell.money.text = @"+1000.00";
    //            return cell;
    //        }
    //        else{
    //            return nil;
    //        }
    //    }
    return nil;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    NSInteger sec = indexPath.section;
    NSInteger vcnum = [_MainViews indexOfObject:tableView];
    if (sec > 0) {
        if (vcnum == 1 ) {
            DetailOrderInfoViewController *nextvc = [[DetailOrderInfoViewController alloc] initWithData:_shoporders[row]];
            [self.navigationController pushViewController:nextvc animated:YES];
        }
        else if (vcnum == 2){
            DetailCodeStoreOrderViewController *nextVC = [[DetailCodeStoreOrderViewController alloc] init];
            [nextVC loadDatawithCode:_integralLsit[row][@"id"]];
            [self.navigationController pushViewController:nextVC animated:YES];
        }
        else if (vcnum == 0){
            NSMutableDictionary *part = _buylist[row];
            DealInfoViewController *nextVC = [[DealInfoViewController alloc] init];
            [nextVC loadWithInfo:part];
            [self.navigationController pushViewController:nextVC animated:YES];
        }
    }
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if ([scrollView isEqual:_BGScroll]) {
        CGFloat contentwid = scrollView.contentOffset.x;
        _noticeView.frame = CGRectMake(contentwid / cxsingler.sellersegnum, 31, cx_wid / cxsingler.sellersegnum, 3);
        NSInteger roundnum = roundf(contentwid / cx_wid);
        if (roundnum != _currentSegNum) {
            _currentSeg.selected = NO;
            _currentSeg = [_segs objectAtIndex:roundnum];
            _currentSeg.selected = YES;
            _currentSegNum = roundnum;
        }
    }
}


#pragma mark--tableview代理结束

-(void)segmentLoad{
    UIView *segview = [[UIView alloc] initWithFrame:CGRectMake(0, cxsingler.topdis + 44, cx_wid, 34)];
    segview.backgroundColor = [UIColor whiteColor];
    UIView *layerview= [[UIView alloc] initWithFrame:CGRectMake(0, 33, cx_wid ,1)];
    layerview.backgroundColor = [CXSinglerModel colorWithHex:@"f3f4f6" alpha:1];
    [segview addSubview:layerview];
    NSArray *segnames = @[@"门店",@"商城",@"分销商城",@"积分池"];
    NSInteger segnum = cxsingler.sellersegnum;
    for (NSInteger index = 0; index < segnum; index ++) {
        
        UIButton *part = [[UIButton alloc] initWithFrame:CGRectMake(cx_wid / segnum * index, 0, cx_wid / segnum, 34)];
        [part setTitle:segnames[index] forState:UIControlStateNormal];
        [part setTitleColor:[CXSinglerModel colorWithHex:@"9b9b9b" alpha:1] forState:UIControlStateNormal];
        [part setTitleColor:[CXSinglerModel colorWithHex:@"fe4438" alpha:1] forState:UIControlStateSelected];
        part.titleLabel.font = [UIFont systemFontOfSize:16];
        [_segs addObject:part];
        WEAKSELF;
        [part cx_eventsBlockHandler:^{
            if (![weakSelf.currentSeg isEqual:part]) {
                weakSelf.currentSeg.selected = NO;
                part.selected = YES;
                weakSelf.currentSeg = part;
                weakSelf.currentSegNum = index;
                [weakSelf.BGScroll setContentOffset:CGPointMake(index * cx_wid, 0) animated:YES];
                [UIView transitionWithView:weakSelf.noticeView duration:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    weakSelf.noticeView.frame = CGRectMake(cx_wid / segnum * index, 31, cx_wid / segnum, 3);
                } completion:nil];
            }
        } forControlEvents:UIControlEventTouchUpInside];
        [segview addSubview:part];
        if (index == 0) {
            part.selected = YES;
            weakSelf.currentSeg = part;
            _noticeView = [[UIView alloc] initWithFrame:CGRectMake(0, 31, cx_wid / segnum, 3)];
            _noticeView.backgroundColor = [CXSinglerModel colorWithHex:@"fe4438" alpha:1];
            [segview addSubview:_noticeView];
        }
    }
    [self.view addSubview:segview];
    
}

-(NSString *)statusByWord:(NSString *)statusWord{
    NSString *returnStr = @"未知";
    if ([statusWord isEqual:@"FINISH"]) {
        returnStr = @"交易完成";
    }
    else if ([statusWord isEqual:@"PAYING"]){
        returnStr = @"待支付";
    }
    else if ([statusWord isEqual:@"WAIT_SHIPPING"]){
        returnStr = @"待发货";
    }
    else if ([statusWord isEqual:@"SHIPPING"]){
        returnStr = @"待收货";
    }
    return returnStr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
